#!/bin/bash
root_dir="/usr/local/edh"
role=$1
mode=$(cat mode)
echo "$(date +"%Y-%m-%d %H:%M:%S") INFO stopping $role in $mode mode"
function stop_master(){
  $root_dir/spark/sbin/stop-master.sh
  if [ $? -eq 0 ];then
    echo "$(date +"%Y-%m-%d %H:%M:%S") INFO stopping master success"
  else
    echo "$(date +"%Y-%m-%d %H:%M:%S") ERROR stopping master fail"
  fi
}

function stop_worker(){
  $root_dir/spark/sbin/stop-worker.sh
  if [ $? -eq 0 ];then
    echo "$(date +"%Y-%m-%d %H:%M:%S") INFO stopping worker success"
  else
    echo "$(date +"%Y-%m-%d %H:%M:%S") ERROR stopping worker fail"
  fi
}



if [ $role == "all" ];then
  stop_master
  stop_worker
fi

if [ $role == "master" ];then
  stop_master
fi

if [ $role == "worker" ];then
  stop_worker
fi